﻿package plugin.xunbao
{
    import morn.core.components.*;
    import morn.core.handlers.*;
    import view.mornExtends.*;
    import vo.*;

    public class CangBag extends View
    {
        private var _curPage:int = 1;
        public var closeBtn:Button;
        public var txt_page:Label;
        public var list:List;
        public var btn_pre:Button;
        public var btn_next:Button;
        protected var uiXML:XML;
        private var needArr:Array;

        public function CangBag()
        {
            this.uiXML = <View>r
n	t	t	t  <Image url=""png.common.cs2_di3nei"" width=""350"" height=""350"" sizeGrid=""10,10,10,10""/>r
n	t	t	t  <List x=""20"" y=""18"" repeatX=""6"" repeatY=""6"" spaceX=""2"" spaceY=""1"" var=""list"">r
n	t	t	t	t<Box name=""render"">r
n	t	t	t	t	t<FlashItem name=""fi"">r
n	t	t	t	t  	t	t<Image url=""jpg.common.cs2_bagcell"" x=""0"" y=""0"" width=""50"" height=""50""/>r
n	t	t	t	t 	t	t<Image url=""png.common.noramlicon"" x=""3"" y=""3"" name=""icon"" width=""42"" height=""42""/>r
n	t	t	t	t 	t  r
n	t	t	t	t	t</FlashItem>r
n	t	t	t	t</Box>r
n	t	t	t  </List>r
n	t	t	t  <Box x=""125"" y=""320"" space=""5"">r
n               <Image url=""png.common.biaoshi"" x=""23"" y=""3""/>r
n	t	t	t	t<Label text=""1/1"" x=""28"" color=""0xc19b66"" y=""5"" var=""txt_page"" stroke=""0x0""/>r
n	t	t	t	t<Button skin=""png.common.btn_zuo"" y=""3"" var=""btn_pre""/>r
n	t	t	t	t<Button skin=""png.common.btn_jiantou"" x=""79"" y=""3"" var=""btn_next""/>r
n	t	t	t  </Box>r
n 	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""324"" var=""closeBtn""/>r
n	t	t	t</View>")("<View>
			  <Image url="png.common.cs2_di3nei" width="350" height="350" sizeGrid="10,10,10,10"/>
			  <List x="20" y="18" repeatX="6" repeatY="6" spaceX="2" spaceY="1" var="list">
				<Box name="render">
					<FlashItem name="fi">
				  		<Image url="jpg.common.cs2_bagcell" x="0" y="0" width="50" height="50"/>
				 		<Image url="png.common.noramlicon" x="3" y="3" name="icon" width="42" height="42"/>
				 	  
					</FlashItem>
				</Box>
			  </List>
			  <Box x="125" y="320" space="5">
               <Image url="png.common.biaoshi" x="23" y="3"/>
				<Label text="1/1" x="28" color="0xc19b66" y="5" var="txt_page" stroke="0x0"/>
				<Button skin="png.common.btn_zuo" y="3" var="btn_pre"/>
				<Button skin="png.common.btn_jiantou" x="79" y="3" var="btn_next"/>
			  </Box>
 			  <Button skin="png.common.btn_cs2_close" x="324" var="closeBtn"/>
			</View>;
            this.needArr = [];
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.closeBtn.clickHandler = new Handler(this.doClose);
            this.btn_pre.clickHandler = new Handler(this.toPre);
            this.btn_next.clickHandler = new Handler(this.toNext);
            return;
        }// end function

        protected function doClose() : void
        {
            this.visible = false;
            return;
        }// end function

        private function toNext() : void
        {
            if (this._curPage >= this.list.totalPage)
            {
                return;
            }
            var _loc_1:String = this;
            var _loc_2:* = this._curPage + 1;
            _loc_1._curPage = _loc_2;
            this.list.page = this._curPage - 1;
            this.txt_page.text = this._curPage + " / " + this.list.totalPage;
            return;
        }// end function

        private function toPre() : void
        {
            if (this._curPage <= 1)
            {
                return;
            }
            var _loc_1:String = this;
            var _loc_2:* = this._curPage - 1;
            _loc_1._curPage = _loc_2;
            this.list.page = this._curPage - 1;
            this.txt_page.text = this._curPage + " / " + this.list.totalPage;
            return;
        }// end function

        public function onShow(param1:Object) : void
        {
            var _loc_9:String = null;
            var _loc_10:Array = null;
            var _loc_11:Object = null;
            var _loc_2:* = ConfigDictionary.data.box;
            if (!_loc_2)
            {
                return;
            }
            var _loc_3:* = ConfigDictionary.data.item;
            var _loc_4:* = int(param1.realtreasure);
            var _loc_5:* = _loc_2[_loc_4];
            var _loc_6:Array = [];
            var _loc_7:* = (_loc_5.items as String).split("#");
            var _loc_8:int = 0;
            while (_loc_8 < (_loc_7.length - 1))
            {
                
                _loc_9 = _loc_7[_loc_8];
                _loc_10 = _loc_9.split("-");
                _loc_11 = ItemObject.create(_loc_3[_loc_10[0]]);
                _loc_11.count = _loc_10[1];
                _loc_6.push(_loc_11);
                _loc_8++;
            }
            this.list.array = _loc_6;
            this.list.renderHandler = new Handler(this.itemRender);
            this._curPage = 1;
            this.list.page = 0;
            this.txt_page.text = this._curPage + " / " + this.list.totalPage;
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            var _loc_3:FlashItem = null;
            if (param2 < this.list.length)
            {
                _loc_3 = param1.getChildByName("fi") as FlashItem;
                _loc_3.data = this.list.array[param2];
            }
            return;
        }// end function

    }
}
